/**
 * This class describe different sublattices for a given lattice
 */
package simulation;

import java.util.ArrayList;

import common.TupleXY;

/**
 * @author vladimir
 * 
 *         parameters: J spatial coupling constant int[][] neighbors array
 *         describing unit cell args size in different dimensions
 */
public class SubLattice {
	public TupleXY[] sub1;// array with first sublattice of the 2D lattice
	public TupleXY[] sub2;// array with second sublattice of the 2D lattice
	public TupleXY[] sub3;// array with third sublattice of the 2D lattice;

	public SubLattice(double J, int[][] neighbors, int... args) {
		int dimension = neighbors[0].length;
		int coordNumber = neighbors.length;
		if (args.length == 1) {
			System.err.println("1D case not yet implemented");
			System.exit(0);
		}
		int X = args[0];
		int Y = args[1];

		if (J > 0) {
			ArrayList<TupleXY> tsub1 = new ArrayList<TupleXY>();
			if (dimension == 2) {
				for (int x = 0; x < X; x++) {
					for (int y = 0; y < Y; y++) {
						tsub1.add(new TupleXY(x, y));
					}
				}
				this.sub1 = toTupleXY(tsub1);
			} else {
				System.err.println("J > 0, 1D, Not yet implemented");
				System.exit(0);
			}
		} else if (J < 0) {
			if (coordNumber == 4) {// Square lattice
				ArrayList<TupleXY> tsub1 = new ArrayList<TupleXY>();
				ArrayList<TupleXY> tsub2 = new ArrayList<TupleXY>();
				if (X % 2 != 0) {
					System.err
							.println("X dimension for square antiferromagnetic should be eval");
					System.exit(0);
				}
				if (Y % 2 != 0) {
					System.err
							.println("Y dimension for square antiferromagnetic should be eval");
					System.exit(0);
				}
				for (int x = 0; x < X; x++) {
					for (int y = 0; y < Y; y++) {
						if ((x + y) % 2 == 0) {
							tsub1.add(new TupleXY(x, y));
						} else if ((x + y) % 2 == 1) {
							tsub2.add(new TupleXY(x, y));
						}
					}
				}
				this.sub1 = toTupleXY(tsub1);
				this.sub2 = toTupleXY(tsub2);
			} else if (coordNumber == 6) {
				ArrayList<TupleXY> tsub1 = new ArrayList<TupleXY>();
				ArrayList<TupleXY> tsub2 = new ArrayList<TupleXY>();
				ArrayList<TupleXY> tsub3 = new ArrayList<TupleXY>();
				if (X % 3 != 0) {
					System.err
							.println("X dimension for the triangular antiferromagnetic should be mod 3");
					System.exit(0);
				}
				if (Y % 3 != 0) {
					System.err
							.println("Y dimension for the triangular antiferromagnetic should be mod 3");
					System.exit(0);
				}
				for (int x = 0; x < X; x++) {
					for (int y = 0; y < Y; y++) {
						if ((x + y) % 3 == 0) {
							tsub1.add(new TupleXY(x, y));
						} else if ((x + y) % 3 == 1) {
							tsub2.add(new TupleXY(x, y));
						} else if ((x + y) % 3 == 2) {
							tsub3.add(new TupleXY(x, y));
						}
					}
				}
				this.sub1 = toTupleXY(tsub1);
				this.sub2 = toTupleXY(tsub2);
				this.sub3 = toTupleXY(tsub3);
			}
		} else {
			System.err.println("Case J = 0 not implemented yet");
			System.exit(0);
		}

	}

	public TupleXY[] toTupleXY(ArrayList<TupleXY> input) {
		TupleXY[] result = new TupleXY[input.size()];
		for (int i = 0; i < input.size(); i++) {
			result[i] = input.get(i);
		}
		return result;
	}
}
